package com.gxa.servlet.goods;

import com.alibaba.fastjson.JSON;
import com.gxa.pojo.Result;
import com.gxa.pojo.goods.Goods;
import com.gxa.pojo.goods.GoodsOneType;
import com.gxa.service.goods.GoodsOneTypeService;
import com.gxa.service.goods.GoodsService;
import com.gxa.service.goods.impl.GoodsOneTypeServiceimpl;
import com.gxa.service.goods.impl.GoodsServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(urlPatterns = "/GoodsSelectServlet")
public class GoodsServlet extends HttpServlet {
    GoodsService goodsService = new GoodsServiceimpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<Goods> goods = goodsService.selectAll();

        Map<String, Object> map = new HashMap<>();
        if (goods!=null){
            map.put("Result", Result.ok("查询成功",goods));
        }else {
            map.put("Result",Result.error());
        }
        String s = JSON.toJSONString(map);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }
}
